package cn.fl.project.service.impl;

import cmm.comm.facade.framework.api.ISysCdMapApiService;
import cmm.comm.facade.framework.api.ISysCtrlCfgApiService;
import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.comm.facade.framework.condition.SysCdMapDQueryCondition;
import cmm.comm.facade.framework.condition.SysCtrlCfgQueryCondition;
import cmm.comm.facade.framework.dto.SysCdMapDDTO;
import cmm.comm.facade.framework.dto.SysDictionaryDTO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.DecimalUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.capital.constant.CapitalConstant;
import cn.fl.customer.service.ICstBankService;
import cn.fl.customer.vo.CstBankVO;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.framework.constant.DictionaryConstant;
import cn.fl.product.service.IMfrInfoService;
import cn.fl.product.service.IPrdCarInfoService;
import cn.fl.product.transform.PrdBscInfoVOTransform;
import cn.fl.product.transform.SplBankVOTransform;
import cn.fl.product.transform.SplInfoVOTransform;
import cn.fl.product.vo.MfrInfoVO;
import cn.fl.product.vo.SplBankVO;
import cn.fl.project.api.IPrjPrdExtApiService;
import cn.fl.project.condition.PrjPrdBscInfoQueryCondition;
import cn.fl.project.condition.PrjSplBankAccRQueryCondition;
import cn.fl.project.constant.PrjPrdBscInfoConstant;
import cn.fl.project.constant.PrjPrdDtlConstant;
import cn.fl.project.dto.PrjPrdBscInfoDTO;
import cn.fl.project.dto.PrjPrdSourceInfoDTO;
import cn.fl.project.service.IPrjPrdBscInfoService;
import cn.fl.project.service.IPrjSplBankAccRService;
import cn.fl.project.service.IProjectApiService;
import cn.fl.project.transform.*;
import cn.fl.project.vo.*;
import cn.fl.system.transform.SysCdMapDVOTransform;
import cn.fl.system.vo.SysCdMapDVO;
import com.alibaba.fastjson.JSON;
import fl.customer.facade.customer.condition.CstBankQueryCondition;
import fl.product.facade.product.api.IProductApiService;
import fl.product.facade.product.condition.PrdBscInfoQueryCondition;
import fl.product.facade.product.dto.PrdBscInfoDTO;
import fl.spl.facade.mfr.condition.MfrInfoQueryCondition;
import fl.spl.facade.spl.api.ISplInfoApiService;
import fl.spl.facade.spl.condition.SplBankQueryCondition;
import fl.spl.facade.spl.condition.SplInfoQueryCondition;
import fl.spl.facade.spl.dto.SplBankDTO;
import fl.spl.facade.spl.dto.SplInfoDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 项目产品基础信息表 客户端服务层接口实现
 * @Description: 业务层方法名称前缀：新增：add* 删除：remove* 修改：modify* 查询对象：select* get* 批量：batch* 查询集合：search*
 */
@Service
public class PrjPrdBscInfoServiceImpl implements IPrjPrdBscInfoService {

	/**
	 * 日志
	 */
	private static final Logger logger = LoggerFactory.getLogger(IPrjPrdBscInfoService.class);
	
	/**
	 * TODO 自定义 API 暴露服务
	 */
	@Autowired
	private IProjectApiService projectApiService;
	
	/**
	 * TODO 自定义 API 暴露服务
	 */
	@Autowired
	private ISysDictionaryApiService sysDictionaryApiService;
	
	@Autowired
	private IProductApiService  productApiService;
	
	@Autowired
	private IPrdCarInfoService prdCarInfoService;

	@Autowired
	private IPrjPrdExtApiService prjPrdExtApiService;
	
	/**
	 * 映射表API服务
	 */
	@Autowired
	private ISysCdMapApiService sysCdMapApiService;
	/**
	 * 
	 */
	@Autowired
	private ISplInfoApiService splInfoApiService;
	
	@Autowired
	private ISysCtrlCfgApiService SysCtrlCfgApiService;
	@Autowired
	private IPrjSplBankAccRService prjSplBankAccRService;
	@Autowired
	private IMfrInfoService mfrInfoService;

	@Autowired
	private ICstBankService cstBankService;

	@Override
	public PrjPrdBscInfoVO selectById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.info(logger, "selectById", "主键参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return null;
		}
		//TODO 业务逻辑
		PrjPrdBscInfoDTO dto = this.projectApiService.selectPrjPrdBscInfoById(id,CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd());
		return PrjPrdBscInfoVOTransform.toVO(dto);
	}

	@Override
	public Long add(PrjPrdBscInfoVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.info(logger, "add", "新增对象不能为空!", CurrentThreadContext.getCurrentUserName());
			return null;
		}
		return this.projectApiService.addPrjPrdBscInfo(PrjPrdBscInfoVOTransform.toDTO(entity));
	}

	@Override
	public boolean removeById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.info(logger, "removeById", "删除主键参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		}
		//return this.prjPrdBscInfoApiService.removeById(id);
		//TODO 业务逻辑
		return false;
	}
	
	/**
     * 删除
     * @param ids
     * @return
     */
    public boolean removeByIds(List<Long> ids)throws BaseException{
    	if(CollectionUtils.isEmpty(ids)){
    		BaseLogUtils.info(logger, "removeByIds", "删除主键参数集合不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		};
		return this.projectApiService.removePrjPrdByIds(ids);
    }

	@Override
	public boolean modify(PrjPrdBscInfoVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.info(logger, "modify", "修改对象参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		}
		return this.projectApiService.modifyProjectApiService(PrjPrdBscInfoVOTransform.toDTO(entity));
	}

	@Override
	public Pager searchListPage(Pager page) throws BaseException{
		if(null == page)page = new Pager();
		Pager pager = this.projectApiService.searchPrjPrdBscListPage(page,CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd());
		if(CollectionUtils.isNotEmpty(pager.getResultList())){
			List<PrjPrdBscInfoDTO> prjPrdList = (List<PrjPrdBscInfoDTO>)pager.getResultList();
			List<Long> prdIdList = new ArrayList<Long>();
			List<Long> splIdList = new ArrayList<Long>();
			List<Long> splBankIdList = new ArrayList<Long>();
			List<Long> cstBankIdList = new ArrayList<Long>();
			for (PrjPrdBscInfoDTO prjPrdBscInfoDTO : prjPrdList) {
				String receiveTypeCd = prjPrdBscInfoDTO.getReceiveTypeCd();
				if(StringUtils.isEmpty(receiveTypeCd)){
					throw new BaseException("收款方类型为空");
				}
				if(null!=prjPrdBscInfoDTO.getPrdId()){
					prdIdList.add(prjPrdBscInfoDTO.getPrdId());
				}
				PrjSplBankAccRQueryCondition accQc = new PrjSplBankAccRQueryCondition();
				accQc.setPrjPrdId(prjPrdBscInfoDTO.getId());
				List<PrjSplBankAccRVO> splBankAccRVOList = 	this.prjSplBankAccRService.searchList(accQc);
				if(CollectionUtils.isNotEmpty(splBankAccRVOList)){
					for (PrjSplBankAccRVO prjSplBankAccRVO : splBankAccRVOList) {
						if(prjSplBankAccRVO.getPurpCd().equals(PrjPrdBscInfoConstant.SPL_BANK_NO_TP)){
							if(CapitalConstant.CODE_PAYEE_TYP_CD_2.equals(receiveTypeCd) || CapitalConstant.CODE_PAYEE_TYP_CD_8.equals(receiveTypeCd)){
								cstBankIdList.add(prjSplBankAccRVO.getSplAccNoId());
							}else{
								splBankIdList.add(prjSplBankAccRVO.getSplAccNoId());
							}
							prjPrdBscInfoDTO.setSplAccNoId(prjSplBankAccRVO.getSplAccNoId());
							break;
						}
					}
				}
				/*if(null!=prjPrdBscInfoDTO.getSplAccNoId()){
					splBankIdList.add(prjPrdBscInfoDTO.getSplAccNoId());
				}*/
				if(null!=prjPrdBscInfoDTO.getSplId() && CapitalConstant.CODE_PAYEE_TYP_CD_1.equals(receiveTypeCd)){
					splIdList.add(prjPrdBscInfoDTO.getSplId());
				}
			}
			List<PrdBscInfoDTO> prdBscList =null;
			if(CollectionUtils.isNotEmpty(prdIdList)){
				PrdBscInfoQueryCondition prdQc = new PrdBscInfoQueryCondition();
				prdQc.setIds(prdIdList);
				prdBscList = this.productApiService.searchPrdBscInfoList(prdQc,CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
			}
			List<SplInfoDTO> splList = null;
			if(CollectionUtils.isNotEmpty(splIdList)){
			SplInfoQueryCondition splQc  = new SplInfoQueryCondition();
			splQc.setIds(splIdList);
			 splList = this.splInfoApiService.searchSplInfoList(splQc,CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
			}
			List<PrjPrdBscInfoVO> list = PrjPrdBscInfoVOTransform.toVOList(prjPrdList);
			if(CollectionUtils.isNotEmpty(splBankIdList)){
			SplBankQueryCondition splBankQc = new SplBankQueryCondition();
			splBankQc.setIdList(splBankIdList);
			List<SplBankDTO> splBankList = this.splInfoApiService.searchPrdSplBkList(splBankQc,CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
			
			if(CollectionUtils.isNotEmpty(list)&&CollectionUtils.isNotEmpty(splBankList)){
				for (PrjPrdBscInfoVO prjPrdBsc : list) {
					for (SplBankDTO splBankDTO : splBankList) {
						if(null!=prjPrdBsc.getSplAccNoId()&&prjPrdBsc.getSplAccNoId().equals(splBankDTO.getId())){
							prjPrdBsc.setSplBankVO(SplBankVOTransform.toVO(splBankDTO));
						}
					}
				}
			}
		}
			if(CollectionUtils.isNotEmpty(cstBankIdList)){
				CstBankQueryCondition cstBankQueryCondition = new CstBankQueryCondition();
				cstBankQueryCondition.setIdList(cstBankIdList);
				List<CstBankVO> cstBankVOS = this.cstBankService.searchList(cstBankQueryCondition);
				if(CollectionUtils.isNotEmpty(list)&&CollectionUtils.isNotEmpty(cstBankVOS)){
					for (PrjPrdBscInfoVO prjPrdBsc : list) {
						for (CstBankVO cstBankVO : cstBankVOS) {
							if(null!=prjPrdBsc.getSplAccNoId()&&prjPrdBsc.getSplAccNoId().equals(cstBankVO.getId())){
								SplBankVO splBankVO = new SplBankVO();
								splBankVO.setRcptUnt(cstBankVO.getAccNm());
								splBankVO.setAccNo(cstBankVO.getAccNo());
								splBankVO.setBkNm(cstBankVO.getBkCdNm());
								splBankVO.setBkNo(cstBankVO.getBkNo());
								prjPrdBsc.setSplBankVO(splBankVO);
							}
						}
					}
				}
			}
			if(CollectionUtils.isNotEmpty(list)&&CollectionUtils.isNotEmpty(prdBscList)){
				for (PrjPrdBscInfoVO prjPrdBsc : list) {
					for (PrdBscInfoDTO prd : prdBscList) {
						if(null!=prjPrdBsc.getPrdId()&&prjPrdBsc.getPrdId().equals(prd.getId())){
							prjPrdBsc.setPrdBscInfoVO(PrdBscInfoVOTransform.toVO(prd));
						}
					}
				}
			}
			
			if(CollectionUtils.isNotEmpty(list)&&CollectionUtils.isNotEmpty(splList)){
				for (PrjPrdBscInfoVO prjPrdBsc : list) {
					for (SplInfoDTO spl : splList) {
						if(null!=prjPrdBsc.getSplId()&&prjPrdBsc.getSplId().equals(spl.getId())){
							prjPrdBsc.setSplInfoVO(SplInfoVOTransform.toVO(spl));
						}
					}
				}
			}
			pager.setResultList(list);
		}
		return pager;
	}

	@Override
	public PrjPrdBscInfoVO selectPrjPrdBscAndDetailInfoById(String id) throws BaseException {
		if(StringUtils.isBlank(id)){
    		BaseLogUtils.info(logger, "selectPrjPrdBscAndDetailInfoById", "id不能为空！", CurrentThreadContext.getCurrentUserName());

		}
		PrjPrdBscInfoDTO prjPrdBscInfoDTO = this.projectApiService.selectPrjPrdBscAndDetailInfoById(id,CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd());
		PrjPrdBscInfoVO prjPrdBscInfo = PrjPrdBscInfoVOTransform.toVO(prjPrdBscInfoDTO);
		String orgCd = CurrentThreadContext.getCurrentOrgCd();
		SysCtrlCfgQueryCondition qc = new SysCtrlCfgQueryCondition();
		qc.setSysCd(CurrentThreadContext.getCurrentSysCd());
		qc.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
		if(orgCd.length()>8){
			if(orgCd.substring(0, 8).equals("00000008")){
				qc.setCtrlCode(DictionaryConstant.CTRL_PRJ_PRD_COUNT_ZK);
			}else{
				qc.setCtrlCode(DictionaryConstant.CTRL_PRJ_PRD_COUNT);
			}
		}else{
			qc.setCtrlCode(DictionaryConstant.CTRL_PRJ_PRD_COUNT);
		}
		String ctrValue=SysCtrlCfgApiService.searchSysCtrlCfgByCtrlCode(qc);
		prjPrdBscInfo.setCtrValue(ctrValue);
		PrjPrdExtVO carInfoVO  = null;
		if(null!=prjPrdBscInfoDTO.getPrjPrdExtDTO()){
			carInfoVO = PrjPrdExtVOTransform.toVO(this.prjPrdExtApiService.selectById(Long.valueOf(prjPrdBscInfoDTO.getId())));
			String carCl = carInfoVO.getCarCl();
			prjPrdBscInfo.setCarCl(carCl);
		}
		if(null!=prjPrdBscInfo.getInvAmt()){
			prjPrdBscInfo.setInvAmt(DecimalUtils.convertFenToYuan(prjPrdBscInfo.getInvAmt().longValue()));
		}
	/*	if(null!=prjPrdBscInfo.getIrrPct()){
			prjPrdBscInfo.setIrrPct(DecimalUtils.convertFenToYuan(prjPrdBscInfo.getIrrPct().longValue()));
		}*/
		if(null!=prjPrdBscInfo.getGuidePc()){
			prjPrdBscInfo.setGuidePc(DecimalUtils.convertFenToYuan(prjPrdBscInfo.getGuidePc().longValue()));
		}
		if(null!=prjPrdBscInfo.getPrdAmt()){
			prjPrdBscInfo.setPrdAmt(DecimalUtils.convertFenToYuan(prjPrdBscInfo.getPrdAmt().longValue()));
		}
		if(null!=prjPrdBscInfo.getRsrvPc()){
			prjPrdBscInfo.setRsrvPc(DecimalUtils.convertFenToYuan(prjPrdBscInfo.getRsrvPc().longValue()));
		}
	/*	StringBuffer sb = new StringBuffer();
		if(null!=prjPrdBscInfo&&null!=prjPrdBscInfo.getPrjPrdTkInfoVO()){
			List<PrjPrdLinkCompRVO>list = prjPrdBscInfo.getPrjPrdTkInfoVO().getPrjPrdLinkCompRVOList();
			if(CollectionUtils.isNotEmpty(list)){
				for (int i=0; i<list.size();i++) {
					PrjPrdLinkCompRVO compRVO = (PrjPrdLinkCompRVO)list.get(i);
					if(i==list.size()-1){
						sb.append(compRVO.getLnkCompId());
					}else{
						sb.append(compRVO.getLnkCompId());
						sb.append(";");
					}

				}
			}
		}
		prjPrdBscInfo.setLnkCompRList(sb.toString());*/
		return prjPrdBscInfo;
	}
	
	
	public PrjPrdBscInfoVO getPrjPrdBscInfoById(Long id) throws BaseException{
		PrjPrdBscInfoVO prjPrdBscInfo =PrjPrdBscInfoVOTransform.toVO(this.projectApiService.getPrjPrdBscInfoById(id));
		if(null!=prjPrdBscInfo.getInvAmt()){
			prjPrdBscInfo.setInvAmt(DecimalUtils.convertFenToYuan(prjPrdBscInfo.getInvAmt().longValue()));
		}
		if(null!=prjPrdBscInfo.getIrrPct()){
			prjPrdBscInfo.setIrrPct(DecimalUtils.convertFenToYuan(prjPrdBscInfo.getIrrPct().longValue()));
		}
		if(null!=prjPrdBscInfo.getGuidePc()){
			prjPrdBscInfo.setGuidePc(DecimalUtils.convertFenToYuan(prjPrdBscInfo.getGuidePc().longValue()));
		}
		if(null!=prjPrdBscInfo.getRsrvPc()){
			prjPrdBscInfo.setRsrvPc(DecimalUtils.convertFenToYuan(prjPrdBscInfo.getRsrvPc().longValue()));
		}
		// 字典码转化
		// 用途代码
		String prdTypCd = prjPrdBscInfo.getPrdTypCd();
		if(StringUtils.isNotBlank(prdTypCd)){
			SysDictionaryDTO pCd = sysDictionaryApiService.getCode("15000", "0000", "CVM0001",prdTypCd );
			if(pCd!=null){
				prjPrdBscInfo.setPrdTypCdNm(pCd.getCodeNm());
			}
		}
		return prjPrdBscInfo;
	}

	@Override
	public List<PrjPrdBscInfoVO> searchList(PrjPrdBscInfoQueryCondition qc) throws BaseException {
		if(qc==null) return null;
		List<PrjPrdBscInfoVO> list = PrjPrdBscInfoVOTransform.toVOList(this.projectApiService.searchPrjPrdList(qc,CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd()));
		if(CollectionUtils.isNotEmpty(list)){
			for (PrjPrdBscInfoVO prjPrdBscInfoVO : list) {
				/**
				 * TODO CustFina 和 VehVal 的值如果在下面分转元 可能会影响调用此方法取值的方法
				 */
				if(null!=prjPrdBscInfoVO.getInvAmt()){
					prjPrdBscInfoVO.setInvAmt(DecimalUtils.convertFenToYuan(prjPrdBscInfoVO.getInvAmt().longValue()));
				}
				if(null!=prjPrdBscInfoVO.getPrdAmt()){
					prjPrdBscInfoVO.setPrdAmt(DecimalUtils.convertFenToYuan(prjPrdBscInfoVO.getPrdAmt().longValue()));
				}
				if(null!=prjPrdBscInfoVO.getGuidePc()){
					prjPrdBscInfoVO.setGuidePc(DecimalUtils.convertFenToYuan(prjPrdBscInfoVO.getGuidePc().longValue()));
				}
                if(null!=prjPrdBscInfoVO.getVehVal()){
                    prjPrdBscInfoVO.setVehVal(DecimalUtils.convertFenToYuan(prjPrdBscInfoVO.getVehVal().longValue()));
                }
                if(null!=prjPrdBscInfoVO.getCustFina()){
                    prjPrdBscInfoVO.setCustFina(DecimalUtils.convertFenToYuan(prjPrdBscInfoVO.getCustFina().longValue()));
                }
			}
		}
	
		return list;
	}

	@Override
	public SysCdMapDVO searchBizCodeByPrdCd(String prdCd) throws BaseException {
		SysCdMapDDTO map = null;
		SysCdMapDQueryCondition qc = new SysCdMapDQueryCondition();
		qc.setmTypCd("M0005");	//映射类型代码
		qc.setSysCd(CurrentThreadContext.getCurrentSysCd());	//系统代码
		qc.setOrgCd(CurrentThreadContext.getCurrentOrgCd());	//目标代码值(组织架构集合)
		//qc.setCodeGrpCd("PRD9999");
		List<SysCdMapDDTO> searchSysCdMapDWithTargetList = this.sysCdMapApiService.searchSysCdMapDWithTargetList(qc);
		if(CollectionUtils.isNotEmpty(searchSysCdMapDWithTargetList)){
			for (SysCdMapDDTO sysCdMapDDTO : searchSysCdMapDWithTargetList) {
				if(sysCdMapDDTO.getTCode().equals(prdCd)){
					map = sysCdMapDDTO;
				}
			}
		}
		 return SysCdMapDVOTransform.toVO(map);
	}

	@Deprecated
	@Override
	public Long addPrjPrdBscAndDetailInfo(PrjPrdBscInfoVO prdBscInfoVO, PrjPrdCarInfoVO prdCarInfoVO,
			PrjPrdTkInfoVO prdTkInfoVO) {
		return this.projectApiService.addPrjPrdBscAndDetailInfo(PrjPrdBscInfoVOTransform.toDTO(prdBscInfoVO),PrjPrdCarInfoVOTransform.toDTO(prdCarInfoVO),PrjPrdTkInfoVOTransform.toDTO(prdTkInfoVO));
	}

	@Override
	public boolean addPrjPrdDtlPrdInfoByDtlId(Long dtlId) throws BaseException {
		if(null==dtlId){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"产品明细ID不能为空！"); 
		}
		return projectApiService.addPrjPrdDtlPrdInfoByDtlId(dtlId,CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd(),CurrentThreadContext.getCurrentUserId());
	}

	@Override
	public List<KeyValueVO> getDrvTypList() throws BaseException {
		String code = DictionaryConstant.CODE_PRD_DRV_TYP_CD;
		return this.getKeyValueList(code);
	}

	@Override
	public List<KeyValueVO> getHpList() throws BaseException {
		String code = DictionaryConstant.CODE_PRD_HP;
		return this.getKeyValueList(code);
	}

	@Override
	public List<KeyValueVO> getGrboxMdlList() throws BaseException {
		String code = DictionaryConstant.CODE_PRD_GRBOX_MDL;
		return this.getKeyValueList(code);
	}

	@Override
	public List<KeyValueVO> getMWhlSpecList() throws BaseException {
		String code = DictionaryConstant.CODE_PRD_M_WHL_SPEC;
		return this.getKeyValueList(code);
	}

	@Override
	public List<KeyValueVO> getMatQalCdList() throws BaseException {
		String code = DictionaryConstant.CODE_PRD_MAT_QAL_CD;
		return this.getKeyValueList(code);
	}

	@Override
	public List<KeyValueVO> getLiftWayCdList() throws BaseException {
		String code = DictionaryConstant.CODE_PRD_LIFT_WAY_CD;
		return this.getKeyValueList(code);
	}

	@Override
	public List<KeyValueVO> getTrlWhlSpecList() throws BaseException {
		String code = DictionaryConstant.CODE_PRD_TRL_WHL_SPEC;
		return this.getKeyValueList(code);
	}

	public List<KeyValueVO> getKeyValueList(String code) throws BaseException {
		List<KeyValueVO>  keyValueList = null;
		List<SysDictionaryDTO>  dictionaryList = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd(),code);
		if(CollectionUtils.isNotEmpty(dictionaryList)){
			keyValueList = new ArrayList<>();
			for (SysDictionaryDTO sysDictionaryDTO : dictionaryList) {
				KeyValueVO keyValue = new KeyValueVO();
				keyValue.setKey(sysDictionaryDTO.getCode());
				keyValue.setValue(sysDictionaryDTO.getCodeNm());
				keyValueList.add(keyValue);
			}
		}
		return keyValueList;
	}

	@Override
	public void removePrjPrdAndPrjPrdPayList(List<Long> idList, Long prjId) throws BaseException {
		//删除项目产品和支付表信息
		this.projectApiService.removePrjPrdAndPrjPrdPayList(idList,prjId);
	}

	@Deprecated
	@Override
	public void modifyPrjPrdBscAndDetailInfo(PrjPrdBscInfoVO prdBscInfoVO, PrjPrdCarInfoVO prdCarInfoVO,
			PrjPrdTkInfoVO prdTkInfoVO) throws BaseException {
		this.projectApiService.modifyPrjPrdBscAndDetailInfo(PrjPrdBscInfoVOTransform.toDTO(prdBscInfoVO),PrjPrdCarInfoVOTransform.toDTO(prdCarInfoVO),PrjPrdTkInfoVOTransform.toDTO(prdTkInfoVO));
	}

	@Override
	public List<SplBankVO> getSplBankAccNoBySplId(SplBankQueryCondition qc) throws BaseException {
		if(null==qc.getSplId()){
			return new ArrayList<SplBankVO>();
		}
		return SplBankVOTransform.toVOList(splInfoApiService.searchPrdSplBkList(qc, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd()));
	}

	@Override
	public Pager searchPrjPrdListPage(Pager page) throws BaseException {
		Pager pager = this.projectApiService.searchPrjPrdListPage(page);
		List<PrjPrdBscInfoVO> list = PrjPrdBscInfoVOTransform.toVOList((List<PrjPrdBscInfoDTO>) pager.getResultList());
		List<Long> prdIdList = new ArrayList<Long>();
		List<Long> splIdList = new ArrayList<Long>();
		
		if(CollectionUtils.isNotEmpty(list)){
			
			for (PrjPrdBscInfoVO prjPrdBscInfoDTO : list) {
				/*if(null!=prjPrdBscInfoDTO.getPrdId()){
					prdIdList.add(prjPrdBscInfoDTO.getPrdId());
				}*/
			
				if(null!=prjPrdBscInfoDTO.getSplId()){
					splIdList.add(prjPrdBscInfoDTO.getSplId());
				}
			}
			/*PrdBscInfoQueryCondition prdQc = new PrdBscInfoQueryCondition();
			prdQc.setIds(prdIdList);
			List<PrdBscInfoDTO> prdBscList = this.productApiService.searchPrdBscInfoList(prdQc,CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());*/
			SplInfoQueryCondition splQc  = new SplInfoQueryCondition();
			splQc.setIds(splIdList);
			List<SplInfoDTO> splList = this.splInfoApiService.searchSplInfoList(splQc,CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
			for (PrjPrdBscInfoVO prjPrdBscInfoVO : list) {
				/*if(null!=prjPrdBscInfoVO.getPrdId()){
					prdIdList.add(prjPrdBscInfoVO.getPrdId());
				}*/
				if(null!=prjPrdBscInfoVO.getSplId()){
					splIdList.add(prjPrdBscInfoVO.getSplId());
				}
				prjPrdBscInfoVO.setGuidePc(DecimalUtils.convertFenToYuan(prjPrdBscInfoVO.getGuidePc().longValue()));
				prjPrdBscInfoVO.setRsrvPc(DecimalUtils.convertFenToYuan(prjPrdBscInfoVO.getRsrvPc().longValue()));
			}
			
			/*if(CollectionUtils.isNotEmpty(list)&&CollectionUtils.isNotEmpty(prdBscList)){
				for (PrjPrdBscInfoVO prjPrdBsc : list) {
					for (PrdBscInfoDTO prd : prdBscList) {
						if(null!=prjPrdBsc.getPrdId()&&prjPrdBsc.getPrdId().equals(prd.getId())){
							prjPrdBsc.setPrdBscInfoVO(PrdBscInfoVOTransform.toVO(prd));
						}
					}
				}
			}*/
			
			if(CollectionUtils.isNotEmpty(list)&&CollectionUtils.isNotEmpty(splList)){
				for (PrjPrdBscInfoVO prjPrdBsc : list) {
					for (SplInfoDTO spl : splList) {
						if(null!=prjPrdBsc.getSplId()&&prjPrdBsc.getSplId().equals(spl.getId())){
							prjPrdBsc.setSplInfoVO(SplInfoVOTransform.toVO(spl));
						}
					}
				}
			}
		}
		pager.setResultList(list);
		return pager;
	}

	@Override
	public Pager searchSplListPage(Pager page) throws BaseException {
		Pager pager = this.splInfoApiService.searchPrdSplInfoListPage(page, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
		List<SplInfoDTO> dtoList = (List<SplInfoDTO>) pager.getResultList();
		pager.setResultList(SplInfoVOTransform.toVOList(dtoList));
		return pager;
	}

	@Override
	public List<MfrInfoVO> getSplMfrListBySplId(SplInfoQueryCondition condition) throws BaseException {
		SplInfoDTO splInfoDTO = this.splInfoApiService.selectPrdSplInfonById(condition.getId(), CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
		if(null==splInfoDTO.getMfrIds()||CollectionUtils.isEmpty(splInfoDTO.getMfrIds())){
			return new ArrayList<MfrInfoVO>();
		}else{
			MfrInfoQueryCondition qc = new MfrInfoQueryCondition();
			qc.setIdList(splInfoDTO.getMfrIds());
			qc.setAudStsCdList(condition.getAudStsCdList());
			qc.setIsValid(condition.getIsValid());
			List<MfrInfoVO>  mfrInfoList = mfrInfoService.searchList(qc);
			return mfrInfoList;
		}
	}

	@Override
	public SysCdMapDVO searchPlcyMapByPrdCd(String prdCd) throws BaseException {
		SysCdMapDDTO map = null;
		SysCdMapDQueryCondition qc = new SysCdMapDQueryCondition();
		qc.setmTypCd("M9001");	//映射类型代码
		qc.setSysCd(CurrentThreadContext.getCurrentSysCd());	//系统代码
		qc.setOrgCd(CurrentThreadContext.getCurrentOrgCd());	//目标代码值(组织架构集合)
		//qc.setCodeGrpCd("PLCY0002");
		List<SysCdMapDDTO> searchSysCdMapDWithTargetList = this.sysCdMapApiService.searchSysCdMapDWithTargetList(qc);
		if(CollectionUtils.isNotEmpty(searchSysCdMapDWithTargetList)){
			for (SysCdMapDDTO sysCdMapDDTO : searchSysCdMapDWithTargetList) {
				if(sysCdMapDDTO.getSCode().equals(prdCd)){
					map = sysCdMapDDTO;
				}
			}
		}
		 return SysCdMapDVOTransform.toVO(map);
	}

	@Override
	public Long selectByPrjId(Long prjId) {
		Long selectByPrjId = this.projectApiService.selectByPrjId(prjId);
		return selectByPrjId;
	}

	@Override
	public Long addPrjPrdBscAndDetailInfo(PrjPrdBscInfoVO prdBscInfoVO, PrjPrdExtVO extDTO) throws BaseException {
		return this.projectApiService.addPrjPrdBscAndDetailInfo(PrjPrdBscInfoVOTransform.toDTO(prdBscInfoVO), PrjPrdExtVOTransform.toDTO(extDTO));
	}

	@Override
	public void modifyPrjPrdBscAndDetailInfo(PrjPrdBscInfoVO prdBscInfoVO, PrjPrdExtVO extDTO) throws BaseException{
		this.projectApiService.modifyPrjPrdBscAndDetailInfo(PrjPrdBscInfoVOTransform.toDTO(prdBscInfoVO),PrjPrdExtVOTransform.toDTO(extDTO));
	}

	@Override
	public void modifyPrjPrdCarSourceDetailInfo(PrjPrdBscInfoVO prdBscInfoVO, PrjPrdExtVO extDTO) throws BaseException{
		this.projectApiService.modifyPrjPrdCarSourceDetailInfo(PrjPrdBscInfoVOTransform.toDTO(prdBscInfoVO),PrjPrdExtVOTransform.toDTO(extDTO));
	}

	@Override
	public int modifyVehCheckCode() {
		return this.projectApiService.modifyVehCheckCode();
	}

	@Override
	public PrjPrdSourceInfoVO selectPrjPrdSourceInfoById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			return null;
		}
		PrjPrdSourceInfoDTO dto = this.projectApiService.selectPrjPrdSourceInfoById(id);
		return PrjPrdSourceInfoVOTransform.toVO(dto);
	}

	@Override
	public void getLoanableAmt(String prjId, String vehNo, Long prjPrdDtlId) {
    	this.projectApiService.getLoanableAmt(prjId, vehNo, prjPrdDtlId);
	}

	@Override
	public boolean checkPrjPrdCarNoExist(PrjPrdBscInfoQueryCondition condition) throws BaseException {
		String carNo = condition.getCarNo();
		boolean flag = false;
		BaseLogUtils.newLogger("根据车源编号查询入参condition:" + JSON.toJSONString(condition)).info();
		List<PrjPrdBscInfoDTO> list = this.projectApiService.getPrjPrdByCarNo(condition);
		BaseLogUtils.newLogger("根据车源编号查询list:" + JSON.toJSONString(list)).info();
		if(CollectionUtils.isNotEmpty(list)){
			for (PrjPrdBscInfoDTO prjPrdBscInfoDTO : list) {
				String str = prjPrdBscInfoDTO.getCarNo().trim();
				if((!prjPrdBscInfoDTO.getPrdStsCd().equals(PrjPrdDtlConstant.CODE_PRJ_PRD_STS_CD_03))
						&&(!prjPrdBscInfoDTO.getPrdStsCd().equals(PrjPrdDtlConstant.CODE_PRJ_PRD_STS_CD_05))
						&&(!prjPrdBscInfoDTO.getPrdStsCd().equals(PrjPrdDtlConstant.CODE_PRJ_PRD_STS_CD_12))
						&&(!prjPrdBscInfoDTO.getPrdStsCd().equals(PrjPrdDtlConstant.CODE_PRJ_PRD_STS_CD_14))
						&&(!prjPrdBscInfoDTO.getPrdStsCd().equals(PrjPrdDtlConstant.CODE_PRJ_PRD_STS_CD_16))
						&&(!prjPrdBscInfoDTO.getPrdStsCd().equals(PrjPrdDtlConstant.CODE_PRJ_PRD_STS_CD_22))
						&&(!prjPrdBscInfoDTO.getPrdStsCd().equals(PrjPrdDtlConstant.CODE_PRJ_PRD_STS_CD_40))
						&&(!prjPrdBscInfoDTO.getPrdStsCd().equals(PrjPrdDtlConstant.CODE_PRJ_PRD_STS_CD_S02))
						&&str.equals(carNo)){
					flag = true;
					break;
				}
			}
		}
		return flag;
	}


	@Override
	public Long addPrdDetailInfoByHC(PrjPrdBscInfoVO prjPrdBscInfo, PrjPrdExtVO extVO, Long oldDtlId, Long paySchId, String paySchNo) throws BaseException {
		return this.projectApiService.addPrdDetailInfoByHC(PrjPrdBscInfoVOTransform.toDTO(prjPrdBscInfo), PrjPrdExtVOTransform.toDTO(extVO), oldDtlId, paySchId, paySchNo);
	}

	@Override
	public void modifyPrdDetailInfoByHC(PrjPrdBscInfoVO prjPrdBscInfo, PrjPrdExtVO extVO, Long oldDtlId) throws BaseException {
		this.projectApiService.modifyPrdDetailInfoByHC(PrjPrdBscInfoVOTransform.toDTO(prjPrdBscInfo), PrjPrdExtVOTransform.toDTO(extVO), oldDtlId);
	}

	/**
	 * 删除
	 * @param id
	 * @return
	 */
	@Override
	public boolean removePrjPrdByHC(Long id, Long paySchId, Long prjId) throws BaseException {
		if (StringUtils.isEmpty(id)) {
			BaseLogUtils.newLogger("removePrjPrdByHC删除项目产品删除主键参数集合不能为空!usrNm:{}", CurrentThreadContext.getCurrentUserName()).info();
			return false;
		}
		return this.projectApiService.removePrjPrdByHC(id, paySchId, prjId);
	}

	@Override
	public void removeGuaranteePaymentInfo(Long prjId) throws BaseException {
		this.projectApiService.removeGuaranteePaymentInfo(prjId);
	}
}
